using System;
using System.Collections.Generic;

public class UserService1106 : IUserService
{
    private List<User1106> _userList = new List<User1106>();

    public bool Register(string username, string password)
    {
        foreach (User1106 user in _userList)
        {
            if (user.Username == username)
            {
                Console.WriteLine("注册失败：用户名已存在！");
                return false;
            }
        }
        _userList.Add(new User1106(username, password));
        Console.WriteLine("注册成功！当前用户总数：" + _userList.Count);
        return true;
    }

    public bool Login(string username, string password)
    {
        foreach (User1106 user in _userList)
        {
            if (user.Username == username && user.Password == password)
            {
                Console.WriteLine("登录成功！欢迎回来，" + username);
                return true;
            }
        }

        Console.WriteLine("登录失败：用户名或密码错误！");
        return false;
    }

    public bool DeleteUser(string username)
    {
        for (int i = 0; i < _userList.Count; i++)
        {
            if (_userList[i].Username == username)
            {
                _userList.RemoveAt(i);
                Console.WriteLine("删除成功！当前用户总数：" + _userList.Count);
                return true;
            }
        }

        Console.WriteLine("删除失败：用户不存在！");
        return false;
    }

    public void Run()
    {
        while (true)
        {
            Console.WriteLine("\n===== 用户系统 =====");
            Console.WriteLine("1. 注册  2. 登录  3. 删除用户  4. 退出");
            Console.Write("请选择操作：");
            string input = Console.ReadLine();

            switch (input)
            {
                case "1":
                    Console.Write("请输入注册用户名：");
                    string regName = Console.ReadLine();
                    Console.Write("请输入注册密码：");
                    string regPwd = Console.ReadLine();
                    Register(regName, regPwd);
                    break;
                case "2":
                    Console.Write("请输入登录用户名：");
                    string loginName = Console.ReadLine();
                    Console.Write("请输入登录密码：");
                    string loginPwd = Console.ReadLine();
                    Login(loginName, loginPwd);
                    break;
                case "3":
                    Console.Write("请输入要删除的用户名：");
                    string delName = Console.ReadLine();
                    DeleteUser(delName);
                    break;
                case "4":
                    Console.WriteLine("程序已退出！");
                    return;
                default:
                    Console.WriteLine("无效操作，请重新选择！");
                    break;
            }
        }
    }
}